<?php
class Test extends public_controller
{
	
	public function __construct() {
		parent:: __construct();
	}

	function index()
	{
		$uploadDir = './data_uploads/person_photo/';        
        if(!is_dir($uploadDir)) {
            mkdir($uploadDir);
            chmod($uploadDir, 0777);
        }
        //$saveDirLarge = substr($uploadDir, 2).'/';

        $config['upload_path'] = $uploadDir;
        $config['allow_flash'] = TRUE;
        $config['allowed_types'] = '*';
        $config['max_size']    = '2048';
        //$config['max_width']  = '1024';
        //$config['max_height']  = '768';
        $config['encrypt_name'] = TRUE;
        $this->load->library('upload', $config);

        if (! $this->upload->do_upload('userfile')){
            echo ($this->upload->display_errors());                       
        } else {
            $dataUpload = $this->upload->data();
            $imgLarge = 'data_uploads/person_photo/'. $dataUpload['file_name'];
            
            $arr_img = array(
                'photo' => $imgLarge,
                'person_id' => $person_id
            );  

            //$this->db->insert('user_avatar', $arr_img);
            $this->db->insert('photo_person', $arr_img);
            
            echo json_encode($this->upload->data());                   
        }  
	}
}